<script setup lang="jsx">
  import {watch,inject,ref,reactive} from 'vue'
  import { Message } from '@arco-design/web-vue'
  import priceAreaList from "@/api/finance/priceAreaList";
  import tool from '@/utils/tool'
  import commonApi from '@/api/common'
  const crudRef = ref()
  const currentRow = ref({ id: undefined, name: undefined })
  const visible = ref(false)

  const open = (row) => {
  currentRow.value = row
  crudRef.value.requestData()
  visible.value = true
}
  let options = reactive({
      id: 'pricelist_id',
      pk: 'id',
      expandSearch:false,
      // 右键菜单配置
      contextMenu: {
        // 是否开启右键菜单
        enabled: false,
      },
      isDbClickEdit:false,
      operationColumn: true,
      operationColumnWidth: 160,
      api: priceAreaList.getList,
      beforeRequest:(param)=>{
        param.area_id = currentRow.value.id
        return param;
      },
      beforeAdd:(param)=>{
        param.area_id = currentRow.value.id
        return param;
      },
      add: {
        show: true,
        api: priceAreaList.save,
        auth: ['finance:priceAreaList:save'],
      },
      edit: {
        show: true,
        api: priceAreaList.update,
        auth: ['finance:priceAreaList:update']
      },
      delete: {
        show: true,
        batch: false,
        api: priceAreaList.deletes,
        auth: ['finance:priceAreaList:delete']
      },
    })

    const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "分区组",
    dataIndex: "area_id",
    formType: "select",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    dict:{
        url: 'finance/priceArea/list',
        props: {label: 'name', value: 'id'},
        params:{
          select:'id,name'
        },
        translation: true,
    },
    search: false
  },
  {
    title: "上级",
    dataIndex: "parent_id",
    formType: "tree-select",
    treeCheckStrictly: true,
    dict:{
        url: 'finance/priceAreaList/tree',
        translation: true,
    },
    search: false
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: "国家",
    dataIndex: "country",
    formType: "input",
    search: false
  },
  // {
  //   title: "邮编开始",
  //   dataIndex: "post_start",
  //   formType: "input",
  //   search: false
  // },
  // {
  //   title: "邮编结束",
  //   dataIndex: "post_end",
  //   formType: "input",
  //   search: false
  // },
  {
    title: "地址库",
    dataIndex: "address_code",
    formType: "input",
    search: true
  },
  {
    title: "邮编匹配",
    dataIndex: "postcode_regexp",
    formType: "input",
    search: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
defineExpose({ open })
</script>

<template>
  <a-drawer width="80%" v-model:visible="visible" :footer="false">
    <template #title>价格表数据</template>
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
</a-drawer>
</template>
<style>


</style>